<?php

namespace app\admin\controller;

use app\common\controller\AdminBase;
use think\Db;

/**
 * 后台首页
 * Class Index
 * @package app\admin\controller
 */
class Index extends AdminBase
{
    protected function _initialize()
    {
        parent::_initialize();
    }

    /**
     * 首页
     * @return mixed
     */
    public function index()
    {
        $version = Db::query('SELECT VERSION() AS ver');
        $config = [
            'url' => $_SERVER['HTTP_HOST'],
            'document_root' => $_SERVER['DOCUMENT_ROOT'],
            'server_os' => PHP_OS,
            'server_port' => $_SERVER['SERVER_PORT'],
            'server_soft' => $_SERVER['SERVER_SOFTWARE'],
            'php_version' => PHP_VERSION,
            'mysql_version' => $version[0]['ver'],
            'max_upload_size' => ini_get('upload_max_filesize')
        ];
        $site_status = Db::name('system')->where(['name' => 'site_status'])->find();

        $this->assign('site_status',$site_status['value']);
        return $this->fetch('index', ['config' => $config]);
    }

    public function changeSiteStatus()
    {
        $state = $this->request->post('state');
        $status = 1;
        if ($state == 'false') {
            $status = 0;
        }
        $rs = Db::name('system')->where(['name' => 'site_status'])->update(['value' => $status]);
        if ($rs) {
            $res = refreshCache('site_status');
            $this->success('修改成功' . $res);
        }
        $this->error('修改失败');
    }
}